/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author shilinghuai
 * @create 2022/4/5
 * @since 1.0.0
 */
public class ReverseLinked {
    public static class MyNode{
            int data;
            MyNode myNode;
            public MyNode(){

            }
            public MyNode(int data,MyNode myNode){
                this.data = data;
                this.myNode = myNode;
            }
    }
    public static class MyStack{
        static MyNode[] myNodes = new MyNode[100];
        static int index = -1;
        public static void push(MyNode myNode){
            myNodes[++index]= myNode;
        }
        public static MyNode pop(){
            if(index==-1){
                return null;
            }
            return myNodes[index--];
        }
    }
    public static void main(String[] args){
        MyNode data3 = new MyNode(3,null);
        MyNode data2 = new MyNode(2,data3);
        MyNode data1= new MyNode(1,data2);
        MyNode head = new MyNode(0,data1);
        //顺序遍历
        MyNode loop = head;
        while (loop.myNode!=null){
            loop = loop.myNode;
            MyStack.push(loop);
        }
        MyNode myNode = MyStack.pop();
        myNode.myNode= null;
        MyNode createLoop = myNode;

        while (true){
            while (createLoop.myNode!=null){
                createLoop = createLoop.myNode;
            }
            createLoop.myNode = MyStack.pop();
            if(createLoop.myNode == null){
                break;
            }
            createLoop.myNode.myNode = null;
        }
        System.out.println(myNode);
    }
}
